import 'dart:convert';

import 'package:base_lib/common/index.dart';
import 'package:base_lib/config.dart';
import '../chat_list/entity/doctor_patient_entity.dart'
    as DoctorPatientBean;
import 'package:doctor_inquiry_lib/repository/inquiry_net_intercept.dart';

class DoctorInquiryHttp {
  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl = Config.doctorBaseUrl,
      codeName = Config.codeName,
      codeSuccessValue = Config.codeSuccessValue,
      msgName = Config.msgName,
      reqTimeOut = Config.reqTimeOut,
      respTimeOut = Config.respTimeOut,
      logTag = "inquiry"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: codeName,
        CODE_SUCCESS_VALUE: codeSuccessValue,
        MSG_NAME: msgName,
        REQ_TIME_OUT: reqTimeOut,
        RESP_TIME_OUT: respTimeOut,
        LOG_TAG: logTag,
        defaultInterceptors: [InquiryNetIntercept()]);
  }

  /// 获取对话列表（全量）
  static const YUNINQUIRY_GET_INQUIRYTALK_TALKLIST =
      "api/yunInquiry/inquiryTalk/getTalksByDoctor";

  /// 根据personID查询患者信息
  static const PEACHUSER_GET_PERSONUSER_PERSONINFOLIST =
      "api/peachUser/personUser/getPersonInfoByPersonIDList";

  /// 获取对话列表（全量）
  static Future<ResultBody<List<DoctorPatientBean.Datum>>> getTalksByDoctor(
      String doctorID) {
    return _httpProxyIns.get<List<DoctorPatientBean.Datum>>(
        YUNINQUIRY_GET_INQUIRYTALK_TALKLIST, (resMap) {
      return DoctorPatientBean.DoctorPatientEntity.fromJson(resMap).data;
    }, queryParams: Map()..['doctorID'] = doctorID);
  }

  /// 根据personID查询患者信息
  static Future<ResultBody<List<DoctorPatientBean.PatientDatum>>> getPersonInfoByPersonIDList(
      String personsID) {
    return _httpProxyIns.get(PEACHUSER_GET_PERSONUSER_PERSONINFOLIST,
        (resMap) {
      return DoctorPatientBean.PatientEntity.fromJson(resMap).data;
    }, queryParams: Map()..['personsID'] = personsID);
  }
}
